home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / SwingSet.java < prev    next >
Text File  |  1998-06-30  |  79KB  |  2,050 lines

  1. /*
  2.  * @(#)SwingSet.java    1.57 98/04/14
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.event.*;
  23. import com.sun.java.swing.text.*;
  24. import com.sun.java.swing.border.*;
  25. import com.sun.java.swing.preview.*;
  26. import com.sun.java.swing.preview.filechooser.*;
  27. import com.sun.java.accessibility.*;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.beans.*;
  32. import java.util.*;
  33. import java.io.*;
  34. import java.applet.*;
  35. import java.net.*;
  36.  
  37. /**
  38.  * A demo that shows all of the Swing components.
  39.  *
  40.  * @version 1.57 04/14/98
  41.  * @author Jeff Dinkins (code, code, and more code)
  42.  * @author Chester Rose (graphic artist)
  43.  * @author Arnaud Weber (applet support)
  44.  * @author Peter Korn   (accessbility support)
  45.  * @author Georges Saab (menus, toolbars)
  46.  */
  47. public class SwingSet extends JPanel
  48. {
  49.     // This
  50.     SwingSet swing;
  51.  
  52.     // The Frame
  53.     public static JFrame frame;
  54.  
  55.     // Current ui
  56.     public String currentUI = "Metal";
  57.  
  58.     // JavaDoc URL
  59.     public static String javaDocPath = null;
  60.  
  61.     // The width and height of the frame
  62.     public static int WIDTH = 790;
  63.     public static int HEIGHT = 550;
  64.     public static int INITIAL_WIDTH = 400;
  65.     public static int INITIAL_HEIGHT = 200;
  66.  
  67.     public final static Dimension hpad5 = new Dimension(5,1);
  68.     public final static Dimension hpad10 = new Dimension(10,1);
  69.     public final static Dimension hpad20 = new Dimension(20,1);
  70.     public final static Dimension hpad25 = new Dimension(25,1);
  71.     public final static Dimension hpad30 = new Dimension(30,1);
  72.     public final static Dimension hpad40 = new Dimension(40,1);
  73.     public final static Dimension hpad80 = new Dimension(80,1);
  74.  
  75.     public final static Dimension vpad5 = new Dimension(1,5);
  76.     public final static Dimension vpad10 = new Dimension(1,10);
  77.     public final static Dimension vpad20 = new Dimension(1,20);
  78.     public final static Dimension vpad25 = new Dimension(1,25);
  79.     public final static Dimension vpad30 = new Dimension(1,30);
  80.     public final static Dimension vpad40 = new Dimension(1,40);
  81.     public final static Dimension vpad80 = new Dimension(1,80);
  82.  
  83.     public final static Insets insets0 = new Insets(0,0,0,0);
  84.     public final static Insets insets5 = new Insets(5,5,5,5);
  85.     public final static Insets insets10 = new Insets(10,10,10,10);
  86.     public final static Insets insets15 = new Insets(15,15,15,15);
  87.     public final static Insets insets20 = new Insets(20,20,20,20);
  88.  
  89.     public final static Border emptyBorder0 = new EmptyBorder(0,0,0,0);
  90.     public final static Border emptyBorder5 = new EmptyBorder(5,5,5,5);
  91.     public final static Border emptyBorder10 = new EmptyBorder(10,10,10,10);
  92.     public final static Border emptyBorder15 = new EmptyBorder(15,15,15,15);
  93.     public final static Border emptyBorder20 = new EmptyBorder(20,20,20,20);
  94.  
  95.     public final static Border etchedBorder10 = new CompoundBorder(
  96.                                                         new EtchedBorder(),
  97.                                                         emptyBorder10);
  98.  
  99.     public final static Border raisedBorder = new BevelBorder(BevelBorder.RAISED);
  100.     public final static Border lightLoweredBorder = new BevelBorder(BevelBorder.LOWERED, 
  101.                                                           Color.white, Color.gray);
  102.     public final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
  103.  
  104.     public Font defaultFont = new Font("Dialog", Font.PLAIN, 12);
  105.     public Font boldFont = new Font("Dialog", Font.BOLD, 12);
  106.     public Font bigFont = new Font("Dialog", Font.PLAIN, 18);
  107.     public Font bigBoldFont = new Font("Dialog", Font.BOLD, 18);
  108.     public Font reallyBigFont = new Font("Dialog", Font.PLAIN, 18);
  109.     public Font reallyBigBoldFont = new Font("Dialog", Font.BOLD, 24);
  110.  
  111.     // L&F radio buttons
  112.     JRadioButtonMenuItem macMenuItem;
  113.     JRadioButtonMenuItem metalMenuItem;
  114.     JRadioButtonMenuItem motifMenuItem;
  115.     JRadioButtonMenuItem windowsMenuItem;
  116.  
  117.     // Some images used in the demo
  118.     public ImageIcon jpgIcon;
  119.     public ImageIcon gifIcon;
  120.  
  121.     public ImageIcon blueDot;
  122.     public ImageIcon redDot;
  123.     public ImageIcon invisibleDot;
  124.  
  125.     public ImageIcon duke2;
  126.     public ImageIcon dukeSnooze;
  127.     public ImageIcon dukeWave;
  128.     public ImageIcon dukeWaveRed;
  129.     public ImageIcon dukeMagnify;
  130.  
  131.     public ImageIcon cow;
  132.  
  133.     public ImageIcon tiger;
  134.     public ImageIcon littleTiger;
  135.  
  136.     public ImageIcon upButton;
  137.     public ImageIcon downButton;
  138.     public ImageIcon disabledButton;
  139.  
  140.  
  141.     // The panels used in the demo
  142.     public JPanel borderPanel;
  143.     public JPanel borderedPanePanel;
  144.     public JPanel buttonPanel;
  145.     public JPanel checkboxPanel;
  146.     public JPanel comboBoxPanel;
  147.     public JPanel dateChooserPanel;
  148.     public JPanel debugGraphicsPanel;
  149.     public JPanel htmlPanel;
  150.     public JPanel labelPanel;
  151.     public JPanel listBoxPanel;
  152.     public JPanel logoPanel;
  153.     public JPanel menuPanel;
  154.     public JPanel progressBarPanel;
  155.     public JPanel radioButtonPanel;
  156.     public JPanel scrollPanePanel;
  157.     public JPanel sliderPanel;
  158.     public JPanel splitPanePanel;
  159.     public JPanel tablePanel;
  160.     public JPanel textPanel;
  161.     public JPanel toggleButtonPanel;
  162.     public JPanel toolTipPanel;
  163.     public JPanel treePanel;
  164.     public JPanel windowPanel;
  165.  
  166.     // Track progress
  167.     public static int totalPanels = 23; // PENDING(jeff) there has got to be a better way...
  168.     public static int currentProgressValue;
  169.     public static JLabel progressLabel = null;
  170.     public static JProgressBar progressBar = null;
  171.  
  172.     // Used when switching to DebugGraphicsPanel
  173.     public Component previousPage;
  174.  
  175.     // Button controls
  176.     public Vector currentControls;
  177.     public Vector labels = new Vector();
  178.     public Vector buttons = new Vector();
  179.     public Vector checkboxes = new Vector();
  180.     public Vector radioButtons = new Vector();
  181.     public Vector toggleButtons = new Vector();
  182.  
  183.     // Some components used in the demo
  184.     public JTabbedPane tabbedPane;
  185.     public JPanel borderedPane;
  186.     public JList listBox;
  187.     public TabPlacementChanger tabPlacement;
  188.     public int toolTipIndex;
  189.  
  190.     // This != null if we are an applet
  191.     java.applet.Applet applet;
  192.     static SwingSet instance;
  193.  
  194.     public SwingSet() {
  195.     this(null);
  196.     }
  197.  
  198.     /*******************************************/
  199.     /****** Construct the SwingSet demo ********/
  200.     /*******************************************/
  201.     public SwingSet(java.applet.Applet anApplet) {
  202.     super(true); // double buffer
  203.  
  204.     instance = this;
  205.     applet = anApplet;
  206.     loadImages();
  207.     swing = this;
  208.     setName("Main SwingSet Panel");
  209.     DebugGraphics.setFlashTime(30);
  210.     setFont(defaultFont);
  211.     setLayout(new BorderLayout());
  212.         currentProgressValue = 0;
  213.  
  214.     // Add a MenuBar
  215.     add(createMenuBar(), BorderLayout.NORTH);
  216.  
  217.     // Create a tab pane
  218.     tabbedPane = new JTabbedPane();
  219.  
  220.         // Add magic key to enable timer logging
  221.     // PENDING(Arnaud) - is this really needed? 
  222.         tabbedPane.registerKeyboardAction(new ToggleLogging(),
  223.              KeyStroke.getKeyStroke('l', InputEvent.ALT_MASK), WHEN_IN_FOCUSED_WINDOW);
  224.         
  225.     // Add the tab to the center
  226.     add(tabbedPane, BorderLayout.CENTER);
  227.  
  228.     // Add the Button panel
  229.     progressLabel.setText("Loading Title Page");
  230.     ImageIcon swingLogo = loadImageIcon("images/swingLabelSmall.gif","Swing!");
  231.     JPanel logoPanel = createLogo();
  232.     tabbedPane.addTab("", swingLogo, logoPanel);
  233.  
  234.     // set the Tab's AccessibleName 'cause we are using a graphic only
  235.     tabbedPane.getAccessibleContext().getAccessibleChild(tabbedPane.indexOfTab(swingLogo)).getAccessibleContext().setAccessibleName("Swing!");
  236.  
  237.     tabbedPane.setSelectedIndex(0);
  238.     progressBar.setValue(++currentProgressValue);
  239.  
  240.     // Buttons
  241.     progressLabel.setText("Loading Button Example");
  242.     buttonPanel = new ButtonPanel(this);
  243.     tabbedPane.addTab("Buttons", null, buttonPanel);
  244.     progressBar.setValue(++currentProgressValue);
  245.  
  246.     // RadioButtons
  247.     progressLabel.setText("Loading RadioButton Example");
  248.     radioButtonPanel = new RadioButtonPanel(this);
  249.     tabbedPane.addTab("RadioButtons", null, radioButtonPanel);
  250.     progressBar.setValue(++currentProgressValue);
  251.  
  252.     // ToggleButtons
  253.     progressLabel.setText("Loading ToggleButton Example");
  254.     toggleButtonPanel = new ToggleButtonPanel(this);
  255.     tabbedPane.addTab("ToggleButtons", null, toggleButtonPanel);
  256.     progressBar.setValue(++currentProgressValue);
  257.  
  258.     // CheckBoxMenuItem
  259.     progressLabel.setText("Loading Checkbox Example");
  260.     checkboxPanel = new CheckboxPanel(this);
  261.     tabbedPane.addTab("Checkboxes", null, checkboxPanel);
  262.     progressBar.setValue(++currentProgressValue);
  263.  
  264.     // Labels
  265.     progressLabel.setText("Loading Label Example");
  266.     labelPanel = new LabelPanel(this);
  267.     tabbedPane.addTab("Labels", null, labelPanel);
  268.     progressBar.setValue(++currentProgressValue);
  269.  
  270.     // Borders
  271.     progressLabel.setText("Loading Border Example");
  272.     borderPanel = new BorderPanel();
  273.     tabbedPane.addTab("Borders", null, borderPanel);
  274.     progressBar.setValue(++currentProgressValue);
  275.  
  276.     // ComboBox
  277.     progressLabel.setText("Loading ComboBox Example");
  278.     comboBoxPanel = new ComboBoxPanel(this);
  279.     tabbedPane.addTab("ComboBox",null,comboBoxPanel);
  280.     progressBar.setValue(++currentProgressValue);
  281.     // This is unfortunately needed right now, since JComboBox
  282.     // has no way to know when an ancestor is removed from
  283.     // the hierarchy so that it can hide its JPopupMenu.  We
  284.     // do this explicitly here so that menus aren't left
  285.     // hanging when you switch tabs -- better underlying 
  286.     // support will exist in future versions.
  287.     tabbedPane.addContainerListener(new ContainerAdapter() {
  288.         public void componentRemoved(ContainerEvent e) {
  289.         Component c = e.getChild();
  290.         if ((c == comboBoxPanel) && (c instanceof ComboBoxPanel)) 
  291.             ((ComboBoxPanel)c).hideAllPopups();
  292.         }
  293.  
  294.     });
  295.  
  296.     // DebugGraphics
  297.     progressLabel.setText("Loading DebugGraphics Example");
  298.     debugGraphicsPanel = new DebugGraphicsPanel(this);
  299.     tabbedPane.addTab("DebugGraphics", null, debugGraphicsPanel);
  300.     progressBar.setValue(++currentProgressValue);
  301.  
  302.     // Internal Frame
  303.     progressLabel.setText("Loading Internal Frame Example");
  304.     windowPanel = new InternalWindowPanel();
  305.     tabbedPane.addTab("Internal Frame", null, windowPanel);
  306.     progressBar.setValue(++currentProgressValue);
  307.  
  308.     // ListBox
  309.     progressLabel.setText("Loading ListBox Example");
  310.     listBoxPanel = new ListPanel(this);
  311.     tabbedPane.addTab("ListBox", null, listBoxPanel);
  312.     progressBar.setValue(++currentProgressValue);
  313.  
  314.     // Menus
  315.     progressLabel.setText("Loading Menu Example");
  316.     menuPanel = createMenus();
  317.     tabbedPane.addTab("Menus & ToolBars", null, menuPanel);
  318.     progressBar.setValue(++currentProgressValue);
  319.     // This is unfortunately needed right now, since JMenu
  320.     // has no way to know when an ancestor is removed from
  321.     // the hierarchy so that it can deselect itself.  We
  322.     // do this explicitly here so that menus aren't left
  323.     // hanging when you switch tabs -- better underlying 
  324.     // support will exist in future versions.
  325.     tabbedPane.addContainerListener(new ContainerAdapter() {
  326.         public void componentRemoved(ContainerEvent e) {
  327.         Component c = e.getChild();
  328.         if (c == menuPanel) 
  329.             menuBar.setSelected(null);
  330.         }
  331.  
  332.     });
  333.  
  334.     // ProgressBar
  335.     progressLabel.setText("Loading ProgressBar Example");
  336.     progressBarPanel = new ProgressPanel(this);
  337.     tabbedPane.addTab("ProgressBar", null, progressBarPanel);
  338.     progressBar.setValue(++currentProgressValue);
  339.  
  340.  
  341.     // ScrollPane
  342.     progressLabel.setText("Loading ScrollPane Example");
  343.     scrollPanePanel = new ScrollPanePanel();
  344.     tabbedPane.addTab("ScrollPane", littleTiger, scrollPanePanel);
  345.     progressBar.setValue(++currentProgressValue);
  346.  
  347.  
  348.     // Sliders
  349.     progressLabel.setText("Loading Slider Example");
  350.     sliderPanel = new SliderPanel(swing);
  351.     tabbedPane.addTab("Slider", null, sliderPanel);
  352.     progressBar.setValue(++currentProgressValue);
  353.  
  354.     // SplitPane
  355.     progressLabel.setText("Loading SplitPane Example");
  356.     splitPanePanel = new SplitPanePanel(this);
  357.     tabbedPane.addTab("SplitPane", null, splitPanePanel);
  358.     progressBar.setValue(++currentProgressValue);
  359.  
  360.  
  361.     // Table
  362.     progressLabel.setText("Loading Table Example");
  363.     tablePanel = new TablePanel(swing);
  364.     tabbedPane.addTab("TableView", null, tablePanel);
  365.     progressBar.setValue(++currentProgressValue);
  366.  
  367.     // Text
  368.     progressLabel.setText("Loading Text Example");
  369.     textPanel = new TextPanel(swing);
  370.     tabbedPane.addTab("Plain Text", null, textPanel);
  371.     progressBar.setValue(++currentProgressValue);
  372.  
  373.     // HTML Text
  374.     // PENDING(jeff) make this work when we are an applet
  375.     if(!isApplet()) {
  376.         progressLabel.setText("Loading HTML Text Example");
  377.         htmlPanel = new HtmlPanel(swing);
  378.         tabbedPane.addTab("HTML Text", null, htmlPanel);
  379.         progressBar.setValue(++currentProgressValue);
  380.     }
  381.  
  382.     // borderedPane
  383.     progressLabel.setText("Loading BorderedPane Example");
  384.     borderedPanePanel = new BorderedPanePanel(this);
  385.     tabbedPane.addTab("BorderedPane", null, borderedPanePanel);
  386.     progressBar.setValue(++currentProgressValue);
  387.  
  388.     // ToolTips
  389.     progressLabel.setText("Loading ToolTip Example");
  390.     toolTipPanel = new ToolTipPanel(swing);
  391.     tabbedPane.addTab("ToolTips", cow, toolTipPanel);
  392.     toolTipIndex = currentProgressValue;
  393.     progressBar.setValue(++currentProgressValue);
  394.  
  395.     // TreeView
  396.     progressLabel.setText("Loading TreeView Example");
  397.     treePanel = new TreePanel(this);
  398.     tabbedPane.addTab("TreeView", null, treePanel);
  399.     progressBar.setValue(++currentProgressValue);
  400.  
  401.     // Add Tab change listener
  402.     createTabListener();
  403.  
  404.     }
  405.  
  406.     class ToggleLogging extends AbstractAction {
  407.         public void actionPerformed(ActionEvent e) {
  408.            Timer.setLogTimers(!Timer.getLogTimers());
  409.         }
  410.  
  411.         public boolean isEnabled() {
  412.             return true;
  413.         }
  414.     }
  415.  
  416.   /** Image loading **/
  417.   void loadImages() {
  418.     jpgIcon = loadImageIcon("images/jpgIcon.jpg", "An icon that represents jpg images");
  419.     gifIcon = loadImageIcon("images/gifIcon.gif", "An icon that represents gif images");
  420.     blueDot   = loadImageIcon("images/dot.gif","A blue bullet icon - to draw attention to a menu item");
  421.     redDot   = loadImageIcon("images/redDot.gif","A red bullet icon - to draw attention to a menu item");
  422.     invisibleDot   = loadImageIcon("images/noDot.gif","An invisible bullet, used in visual spacing of menu items");
  423.     duke2 = loadImageIcon("images/duke2.gif","Duke with hands at sides");
  424.     dukeSnooze = loadImageIcon("images/dukeSnooze.gif","Sleeping Duke");
  425.     dukeWave   = loadImageIcon("images/dukeWave.gif","Duke waving");
  426.     dukeWaveRed = loadImageIcon("images/dukeWaveRed.gif","Duke waving with bright red nose");
  427.     dukeMagnify = loadImageIcon("images/dukeMagnify.gif","Duke with a magnifying glass");
  428.     cow         = loadImageIcon("images/cowSmall.gif","Black and white cow");
  429.     tiger       = loadImageIcon("images/BigTiger.gif","Fierce looking tiger");
  430.     littleTiger = loadImageIcon("images/SmallTiger.gif","Fierce looking tiger");
  431.     upButton    = loadImageIcon("images/buttonImage2.gif","Round button with gold border, green on the inside, and dark triangle pointing right.");
  432.     downButton  = loadImageIcon("images/buttonImage3.gif","Round button with gold border, green on the inside, and green triangle pointing right.");
  433.     disabledButton = loadImageIcon("images/buttonImage4.gif","Round button with gold border, green on the inside, and greyed out triangle pointing right.");
  434.   }
  435.  
  436.     private class AccessibilityEasterListener extends MouseAdapter {
  437.         StringTokenizer descriptionTokens;
  438.         String descriptionText;
  439.     JMenuItem menuItem;
  440.         public AccessibilityEasterListener(JMenuItem mi, String descs) {
  441.         super();
  442.         descriptionTokens = new StringTokenizer(descs, ",");
  443.         descriptionText = descs;
  444.         menuItem = mi;
  445.         }
  446.  
  447.         public void mouseEntered(MouseEvent e) {
  448.             if (!descriptionTokens.hasMoreTokens()) {
  449.             descriptionTokens = new StringTokenizer(descriptionText, ",");
  450.             }
  451.             menuItem.getAccessibleContext().setAccessibleDescription(descriptionTokens.nextToken());
  452.         }
  453.     }
  454.  
  455.     /*******************************************/
  456.     /************ create components ************/
  457.     /*******************************************/
  458.  
  459.     /**
  460.      * MenuBar
  461.      */
  462.     Dialog aboutBox;
  463.     JCheckBoxMenuItem cb;
  464.     JRadioButtonMenuItem rb;
  465.  
  466.     JMenuBar createMenuBar() {
  467.     // MenuBar
  468.     JMenuBar menuBar = new JMenuBar();
  469.     menuBar.getAccessibleContext().setAccessibleName("Swing menus");
  470.  
  471.     JMenuItem mi;
  472.  
  473.     // File Menu
  474.     JMenu file = (JMenu) menuBar.add(new JMenu("File"));
  475.         file.setMnemonic('F');
  476.     file.getAccessibleContext().setAccessibleDescription("The standard 'File' application menu");
  477.         mi = (JMenuItem) file.add(new JMenuItem("About"));
  478.         mi.setMnemonic('t');
  479.     mi.getAccessibleContext().setAccessibleDescription("Find out about the SwingSet application");
  480.     mi.addActionListener(new ActionListener() {
  481.         public void actionPerformed(ActionEvent e) {
  482.         // tabbedPane.setSelectedIndex(0);
  483.                 if(aboutBox == null) {
  484.                     aboutBox = new Dialog(SwingSet.sharedInstance().getFrame(), "About Swing!", false);
  485.                     JPanel groupPanel = new JPanel(new BorderLayout());
  486.             ImageIcon groupPicture = loadImageIcon("images/Copyright.gif",
  487.                       "SwingSet demo is Copyright (c) 1997 Sun Microsystems, Inc.  All Rights Reserved.");
  488.                     aboutBox.add(groupPanel, BorderLayout.CENTER);
  489.             JLabel groupLabel = (new JLabel(groupPicture));
  490.             groupLabel.getAccessibleContext().setAccessibleName("SwingSet demo Copyright");
  491.             groupLabel.getAccessibleContext().setAccessibleDescription("The JFC Swing Toolkit is a cooperative effort between JavaSoft and Netscape.  The SwingSet demo is Copyright 1997 Sun Microsystems, Inc.  All Rights Reserved.");
  492.                     groupPanel.add(groupLabel, BorderLayout.CENTER);
  493.                     JPanel buttonPanel = new JPanel(true);
  494.                     groupPanel.add(buttonPanel, BorderLayout.SOUTH);
  495.                     JButton button = (JButton) buttonPanel.add(new JButton("OK"));
  496.                     button.addActionListener(new ActionListener() {
  497.                         public void actionPerformed(ActionEvent e) {
  498.                             aboutBox.setVisible(false);
  499.                         }
  500.                     });
  501.                 }
  502.         aboutBox.pack();
  503.         aboutBox.show();
  504.         }
  505.     });
  506.  
  507.         file.add(new JSeparator());
  508.         mi = (JMenuItem) file.add(new JMenuItem("Open"));
  509.         mi.setMnemonic('O');
  510.     mi.setEnabled(false);
  511.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for opening a file");
  512.         mi = (JMenuItem) file.add(new JMenuItem("Save"));
  513.         mi.setMnemonic('S');
  514.     mi.setEnabled(false);
  515.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for saving a file");
  516.         mi = (JMenuItem) file.add(new JMenuItem("Save As..."));
  517.         mi.setMnemonic('A');
  518.     mi.setEnabled(false);
  519.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for saving a file with a new name");
  520.         file.add(new JSeparator());
  521.         mi = (JMenuItem) file.add(new JMenuItem("Exit"));
  522.         mi.setMnemonic('x');
  523.     mi.getAccessibleContext().setAccessibleDescription("Exit the SwingSet application");
  524.     mi.addActionListener(new ActionListener() {
  525.         public void actionPerformed(ActionEvent e) {
  526.         System.exit(0);
  527.         }
  528.     }
  529.     );
  530.  
  531.     // Options Menu
  532.     JMenu options = (JMenu) menuBar.add(new JMenu("Options"));
  533.         options.setMnemonic('p');
  534.     options.getAccessibleContext().setAccessibleDescription("Look and Feel options: select one of several different Look and Feels for the SwingSet application");
  535.  
  536.         // Look and Feel Radio control
  537.     ButtonGroup group = new ButtonGroup();
  538.     ToggleUIListener toggleUIListener = new ToggleUIListener();
  539.         windowsMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Windows Style Look and Feel"));
  540.     windowsMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Windows"));
  541.     group.add(windowsMenuItem);
  542.     windowsMenuItem.addItemListener(toggleUIListener);
  543.     windowsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
  544.  
  545.         motifMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Motif Look and Feel"));
  546.     motifMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("CDE/Motif"));
  547.     group.add(motifMenuItem);
  548.     motifMenuItem.addItemListener(toggleUIListener);
  549.     motifMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
  550.  
  551.         metalMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Metal Look and Feel"));
  552.     metalMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Metal"));
  553.     metalMenuItem.setSelected(true);
  554.     group.add(metalMenuItem);
  555.     metalMenuItem.addItemListener(toggleUIListener);
  556.     metalMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
  557.  
  558.     // Not shipped yet with full Swing release
  559.         /*
  560.       macMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Macintosh Look and Feel"));
  561.       macMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Macintosh"));
  562.       group.add(macMenuItem);
  563.       macMenuItem.addItemListener(toggleUIListener);
  564.       macMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK));
  565.     */
  566.  
  567.     // non-supported stuff
  568.     /*  
  569.         rb = (JRadioButtonMenuItem)
  570.             options.add(new JRadioButtonMenuItem("Metal Look and Feel (High Contrast Theme)"));
  571.         rb.setSelected(UIManager.getLookAndFeel().getName().equals("Metal HCT"));
  572.         group.add(rb);
  573.         rb.addItemListener(toggleUIListener);
  574.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK));
  575.         
  576.         rb = (JRadioButtonMenuItem)
  577.              options.add(new JRadioButtonMenuItem("Organic Look and Feel (Santa Fe)"));
  578.         rb.getAccessibleContext().setAccessibleDescription(
  579.              "The Organic Look and Feel with a brown/yellow color scheme");
  580.         rb.setSelected(UIManager.getLookAndFeel().getName().equals("Java"));
  581.         group.add(rb);
  582.         rb.addItemListener(toggleUIListener);
  583.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, ActionEvent.ALT_MASK));
  584.         
  585.         rb = (JRadioButtonMenuItem)
  586.             options.add(new JRadioButtonMenuItem("Organic Look and Feel (Vancouver)"));
  587.         rb.getAccessibleContext().setAccessibleDescription(
  588.             "The Organic Look and Feel with a neutral grey color scheme");
  589.         group.add(rb);
  590.         rb.addItemListener(toggleUIListener);
  591.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, ActionEvent.ALT_MASK));
  592.         
  593.         rb = (JRadioButtonMenuItem)
  594.             options.add(new JRadioButtonMenuItem("Organic Look and Feel (Dallas)"));
  595.         rb.getAccessibleContext().setAccessibleDescription(
  596.             "The Organic Look and Feel with a high contrast color scheme and large print");
  597.         group.add(rb);
  598.         rb.addItemListener(toggleUIListener);
  599.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, ActionEvent.ALT_MASK));
  600.     */
  601.  
  602.         // Tab Placement submenu
  603.         options.add(new JSeparator());
  604.  
  605.         tabPlacement = new TabPlacementChanger();
  606.     tabPlacement.getAccessibleContext().setAccessibleDescription(
  607.            "Sub-menu containing options for placement of the TabbedPane");
  608.         options.add(tabPlacement);
  609.  
  610.         // Tooltip checkbox
  611.         options.add(new JSeparator());
  612.  
  613.         cb = (JCheckBoxMenuItem) options.add(new JCheckBoxMenuItem("Show ToolTips"));
  614.     cb.setSelected(true);
  615.  
  616.     cb.addActionListener(new ActionListener() {
  617.         public void actionPerformed(ActionEvent e) {
  618.         JCheckBoxMenuItem cb = (JCheckBoxMenuItem)e.getSource();
  619.         if(cb.isSelected()) {
  620.                     ToolTipManager.sharedInstance().setEnabled(true);
  621.         } else {
  622.                     ToolTipManager.sharedInstance().setEnabled(false);
  623.         }
  624.         }
  625.     });
  626.  
  627.     ActionListener easterListener = new ActionListener() {
  628.         public void actionPerformed(ActionEvent e) {
  629.         tabbedPane.setSelectedIndex(toolTipIndex);
  630.         ((ToolTipPanel)toolTipPanel).itsEaster(true);
  631.         swing.invalidate();
  632.         swing.validate();
  633.         swing.repaint();
  634.         }
  635.     };
  636.  
  637.     // Contributors Menu
  638.     JMenu people = (JMenu) menuBar.add(new JMenu("Contributors"));
  639.         people.setMnemonic('A');
  640.     people.getAccessibleContext().setAccessibleDescription(
  641.             "Listing of all of the individual contributors to Swing");
  642.  
  643.         mi = (JMenuItem) people.add(new JMenuItem("Michael Albers", invisibleDot));
  644.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  645.  
  646.         mi = (JMenuItem) people.add(new JMenuItem("Mark Andrews", invisibleDot));
  647.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  648.  
  649.         mi = (JMenuItem) people.add(new JMenuItem("Tom Ball", blueDot));
  650.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  651.     mi.addActionListener(easterListener);
  652.  
  653.         mi = (JMenuItem) people.add(new JMenuItem("Alan Chung", invisibleDot));
  654.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  655.  
  656.         mi = (JMenuItem) people.add(new JMenuItem("Jeff Dinkins", blueDot));
  657.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  658.     mi.addActionListener(easterListener);
  659.  
  660.         mi = (JMenuItem) people.add(new JMenuItem("Amy Fowler", blueDot));
  661.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  662.     mi.addActionListener(easterListener);
  663.  
  664.         mi = (JMenuItem) people.add(new JMenuItem("Brian Gerhold", invisibleDot));
  665.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  666.  
  667.         mi = (JMenuItem) people.add(new JMenuItem("Makarand Gokhale", invisibleDot));
  668.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  669.  
  670.         mi = (JMenuItem) people.add(new JMenuItem("James Gosling", blueDot));
  671.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  672.     mi.addActionListener(easterListener);
  673.  
  674.         mi = (JMenuItem) people.add(new JMenuItem("David Karlton", invisibleDot));
  675.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  676.  
  677.         mi = (JMenuItem) people.add(new JMenuItem("Dave Kloba", redDot));
  678.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  679.     mi.addActionListener(new ActionListener() {
  680.         public void actionPerformed(ActionEvent e) {
  681.         tabbedPane.setSelectedIndex(toolTipIndex);
  682.         ((ToolTipPanel)toolTipPanel).itsEaster(false);
  683.         swing.invalidate();
  684.         swing.validate();
  685.         swing.repaint();
  686.         }
  687.     });
  688.  
  689.         mi = (JMenuItem) people.add(new JMenuItem("Peter Korn", invisibleDot));
  690.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  691.     mi.addMouseListener(new AccessibilityEasterListener(mi, "Wrote Accessibility API,Wrote outSPOKEN for Windows,Wrote GUIAccess for Windows,Contributed to outSPOKEN for Macintosh,Contributed to inLARGE for Macintosh"));
  692.  
  693.         mi = (JMenuItem) people.add(new JMenuItem("Rick Levenson", blueDot));
  694.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  695.     mi.addActionListener(easterListener);
  696.  
  697.         mi = (JMenuItem) people.add(new JMenuItem("Dana Miller", invisibleDot));
  698.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  699.  
  700.         mi = (JMenuItem) people.add(new JMenuItem("Philip Milne", blueDot));
  701.  
  702.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  703.     mi.addActionListener(easterListener);
  704.  
  705.         mi = (JMenuItem) people.add(new JMenuItem("Dave Moore", invisibleDot));
  706.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  707.  
  708.         mi = (JMenuItem) people.add(new JMenuItem("Hans Muller", blueDot));
  709.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  710.     mi.addActionListener(easterListener);
  711.  
  712.         mi = (JMenuItem) people.add(new JMenuItem("Jill Nakata", invisibleDot));
  713.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  714.  
  715.         mi = (JMenuItem) people.add(new JMenuItem("Tim Prinzing", blueDot));
  716.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  717.     mi.addActionListener(easterListener);
  718.  
  719.         mi = (JMenuItem) people.add(new JMenuItem("Chester Rose", invisibleDot));
  720.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  721.  
  722.         mi = (JMenuItem) people.add(new JMenuItem("Chris Ryan", invisibleDot));
  723.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  724.  
  725.         mi = (JMenuItem) people.add(new JMenuItem("Ray Ryan", invisibleDot));
  726.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  727.  
  728.         mi = (JMenuItem) people.add(new JMenuItem("Georges Saab", blueDot));
  729.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  730.     mi.addActionListener(easterListener);
  731.  
  732.         mi = (JMenuItem) people.add(new JMenuItem("Tom Santos", invisibleDot));
  733.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  734.  
  735.         mi = (JMenuItem) people.add(new JMenuItem("Jeff Shapiro", invisibleDot));
  736.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  737.  
  738.         mi = (JMenuItem) people.add(new JMenuItem("Joseph Scheuhammer", invisibleDot));
  739.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  740.  
  741.         mi = (JMenuItem) people.add(new JMenuItem("Rich Schiavi", blueDot));
  742.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  743.     mi.addActionListener(easterListener);
  744.  
  745.         mi = (JMenuItem) people.add(new JMenuItem("Nancy Schorr", invisibleDot));
  746.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  747.  
  748.         mi = (JMenuItem) people.add(new JMenuItem("Sara Swanson", invisibleDot));
  749.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  750.  
  751.         mi = (JMenuItem) people.add(new JMenuItem("Harry Vertelney", invisibleDot));
  752.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  753.  
  754.         mi = (JMenuItem) people.add(new JMenuItem("Scott Violet", invisibleDot));
  755.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  756.  
  757.         mi = (JMenuItem) people.add(new JMenuItem("Willie Walker", invisibleDot));
  758.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  759.     mi.addMouseListener(new AccessibilityEasterListener(mi, "Wrote Java Accessibility API,Wrote AccessX,Designed RAP prototol,Contributor to UltraSonix"));
  760.  
  761.         mi = (JMenuItem) people.add(new JMenuItem("Kathy Walrath", invisibleDot));
  762.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  763.  
  764.         mi = (JMenuItem) people.add(new JMenuItem("Arnaud Weber", blueDot));
  765.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  766.     mi.addActionListener(easterListener);
  767.  
  768.         mi = (JMenuItem) people.add(new JMenuItem("Steve Wilson", invisibleDot));
  769.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  770.  
  771.     // Chooser Menu
  772.     JMenu choosers = (JMenu) menuBar.add(new JMenu("Choosers"));
  773.     choosers.setMnemonic('H');
  774.     choosers.getAccessibleContext().setAccessibleDescription("Invoke one of the Swing Choosers");
  775.     mi = (JMenuItem) choosers.add(new JMenuItem("Color Chooser"));
  776.     ActionListener startColorChooser = new ActionListener() {
  777.         public void actionPerformed(ActionEvent e) {
  778.         tabbedPane.setSelectedIndex(toolTipIndex);
  779.         Color color = JColorChooser.showDialog(SwingSet.this, "Color Chooser", getBackground());
  780.         toolTipPanel.setBackground(color); 
  781.         toolTipPanel.repaint();
  782.         
  783.         }
  784.     };
  785.     mi.addActionListener(startColorChooser);
  786.     
  787.     if(!isApplet()) {
  788.         mi = (JMenuItem) choosers.add(new JMenuItem("File Chooser"));
  789.         ActionListener startFileChooser = new ActionListener() {
  790.         public void actionPerformed(ActionEvent e) {
  791.             JFileChooser chooser = new JFileChooser();
  792.             ExampleFileFilter filter = new ExampleFileFilter(
  793.             new String[] {"jpg", "gif"}, "JPEG and GIF Image Files"
  794.             );
  795.             ExampleFileView fileView = new ExampleFileView();
  796.             fileView.putIcon("jpg", jpgIcon);
  797.             fileView.putIcon("gif", gifIcon);
  798.             chooser.setFileView(fileView);
  799.             chooser.addChoosableFileFilter(filter);
  800.             chooser.setFileFilter(filter);
  801.             chooser.setAccessory(new FilePreviewer(chooser));
  802.  
  803.             File swingFile = new File("images/swing-64.gif");
  804.             if(swingFile.exists()) {
  805.             chooser.setCurrentDirectory(swingFile);
  806.             chooser.setSelectedFile(swingFile);
  807.             } else {
  808. System.out.println("swingFile doesn't exist )-: -- " + swingFile.getAbsolutePath());
  809.             }
  810.  
  811.             int retval = chooser.showOpenDialog(SwingSet.this);
  812.             if(retval == 0) {
  813.             File theFile = chooser.getSelectedFile();
  814.             if(theFile != null) {
  815.                 JOptionPane.showMessageDialog(SwingSet.this, "You chose this file: " +
  816.                               chooser.getSelectedFile().getAbsolutePath());
  817.                 return;
  818.             }
  819.             } 
  820.             JOptionPane.showMessageDialog(SwingSet.this, "No file chosen");
  821.         }
  822.         };
  823.         mi.addActionListener(startFileChooser);
  824.     }
  825.  
  826.     createOptionsMenu(menuBar);
  827.     return menuBar;
  828.     }
  829.  
  830.     /**
  831.      * Menus
  832.      */
  833.     JMenuBar menuBar;
  834.  
  835.     JPanel createMenus() {
  836.     JPanel p = createVerticalPanel(true);
  837.     p.setBorder(emptyBorder10);
  838.  
  839.     // ********************
  840.     // ***** MenuBar ******
  841.     // ********************
  842.     JLabel l = new JLabel("Menus:");
  843.     l.setAlignmentX(LEFT_ALIGNMENT);
  844.     l.setAlignmentY(TOP_ALIGNMENT);
  845.     l.setFont(boldFont);
  846.     p.add(l);
  847.     p.add(Box.createRigidArea(vpad10));
  848.     menuBar = new JMenuBar();
  849.     menuBar.getAccessibleContext().setAccessibleName(l.getText());
  850.     menuBar.setAlignmentX(LEFT_ALIGNMENT);
  851.     menuBar.setAlignmentY(TOP_ALIGNMENT);
  852.     p.add(menuBar);
  853.     p.add(Box.createRigidArea(vpad40));
  854.     l.setLabelFor(menuBar);    // make label Mnemonic go to menu bar
  855.     l.setDisplayedMnemonic('m');
  856.  
  857.     // File
  858.     JMenu file = (JMenu) menuBar.add(new JMenu("File"));
  859.     file.setMnemonic('i');
  860.     JMenuItem newItem =
  861.     file.add(new JMenuItem("New", loadImageIcon("images/new.gif","New")));
  862.     newItem.setHorizontalTextPosition(JButton.RIGHT);
  863.     newItem.setMnemonic('N');
  864.     JMenuItem open = (JMenuItem)
  865.     file.add(new JMenuItem("Open", loadImageIcon("images/open.gif","Open")));
  866.     open.setHorizontalTextPosition(JButton.RIGHT);
  867.     open.setMnemonic('O');
  868.     JMenuItem save = (JMenuItem)
  869.     file.add(new JMenuItem("Save", loadImageIcon("images/save.gif","Save")));
  870.     save.setHorizontalTextPosition(JButton.RIGHT);
  871.     save.setMnemonic('S');
  872.  
  873.     // Edit
  874.     JMenu edit = (JMenu) menuBar.add(new JMenu("Edit"));
  875.     edit.setMnemonic('E');
  876.     JMenuItem cut = (JMenuItem)
  877.     edit.add(new JMenuItem("Cut", loadImageIcon("images/cut.gif","Cut")));
  878.     cut.setHorizontalTextPosition(JButton.RIGHT);
  879.     cut.setMnemonic('t');
  880.     JMenuItem copy = (JMenuItem)
  881.     edit.add(new JMenuItem("Copy", loadImageIcon("images/copy.gif","Copy")));
  882.     copy.setHorizontalTextPosition(JButton.RIGHT);
  883.     copy.setMnemonic('C');
  884.     JMenuItem paste = (JMenuItem)
  885.     edit.add(new JMenuItem("Paste", loadImageIcon("images/paste.gif","Paste")));
  886.     paste.setHorizontalTextPosition(JButton.RIGHT);
  887.     paste.setMnemonic('P');
  888.  
  889.     // Letters
  890.     JMenu letters = (JMenu) menuBar.add(new JMenu("Letters "));
  891.     letters.setMnemonic('t');
  892.  
  893.     JMenu letterMenu;
  894.     JMenu subMenu;
  895.         JMenu tmpMenu;
  896.  
  897.     // C
  898.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("A")));
  899.         tmpMenu.setMnemonic('A');
  900.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Airplane"));
  901.           subMenu.add(new JMenuItem("Cessna 152"));
  902.           subMenu.add(new JMenuItem("Boeing 747"));
  903.           subMenu.add(new JMenuItem("Piper Cherokee"));
  904.  
  905.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Alicia Silverstone"));
  906.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Clueless"));
  907.       cb.setSelected(true);
  908.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Batman"));
  909.  
  910.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Apple"));
  911.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Fuji"));
  912.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Granny Smith"));
  913.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Macintosh"));
  914.       cb.setSelected(true);
  915.  
  916.     // B
  917.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("B")));
  918.         tmpMenu.setMnemonic('B');
  919.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Swing Babies!"));
  920.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Ewan"));
  921.       cb.setSelected(true);
  922.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Matthew"));
  923.       cb.setSelected(true);
  924.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Montana"));
  925.       cb.setSelected(true);
  926.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Nathan"));
  927.       cb.setSelected(true);
  928.  
  929.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Band"));
  930.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Alice In Chains"));
  931.       cb.setSelected(true);
  932.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("King Crimson"));
  933.       cb.setSelected(true);
  934.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Meat Puppets"));
  935.       cb.setSelected(true);
  936.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Rush"));
  937.       cb.setSelected(true);
  938.  
  939.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Baywatch"));
  940.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Pam Anderson"));
  941.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("David Hasslehoff"));
  942.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Yasmine Bleeth"));
  943.       cb.setSelected(true);
  944.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Carmine Electra"));
  945.  
  946.     // C
  947.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("C")));
  948.         tmpMenu.setMnemonic('c');
  949.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cookie"));
  950.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Chocolate Chip"));
  951.       cb.setSelected(true);
  952.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Fortune"));
  953.       cb.setSelected(true);
  954.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Oatmeal"));
  955.       cb.setSelected(true);
  956.  
  957.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cool"));
  958.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("James Dean"));
  959.       cb.setSelected(true);
  960.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("The Fonz"));
  961.       cb.setSelected(true);
  962.  
  963.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cats"));
  964.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Ridley"));
  965.       cb.setSelected(true);
  966.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Quigley"));
  967.       cb.setSelected(true);
  968.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Kizmet "));
  969.       cb.setSelected(true);
  970.  
  971.  
  972.     // Colors
  973.     JMenu colors = (JMenu) menuBar.add(new JMenu("Colors"));
  974.     colors.setMnemonic('C');
  975.     colors.setHorizontalTextPosition(JButton.RIGHT);
  976.     colors.setIcon(new ColoredSquare(Color.orange));
  977.     menuBar.validate();
  978.  
  979.         JMenuItem red = colors.add(new JMenuItem("Red"));
  980.     red.setHorizontalTextPosition(JButton.RIGHT);
  981.     red.setIcon(new ColoredSquare(Color.red));
  982.  
  983.         JMenuItem blue = colors.add(new JMenuItem("Blue"));
  984.     blue.setHorizontalTextPosition(JButton.RIGHT);
  985.     blue.setIcon(new ColoredSquare(Color.blue));
  986.  
  987.         JMenuItem green = colors.add(new JMenuItem("Green"));
  988.     green.setHorizontalTextPosition(JButton.RIGHT);
  989.     green.setIcon(new ColoredSquare(Color.green));
  990.  
  991.         JMenuItem yellow = colors.add(new JMenuItem("Yellow"));
  992.     yellow.setHorizontalTextPosition(JButton.RIGHT);
  993.     yellow.setIcon(new ColoredSquare(Color.yellow));
  994.  
  995.     // Numbers
  996.     JMenu numbers = (JMenu) menuBar.add(new JMenu("Numbers"));
  997.     numbers.setMnemonic('u');
  998.         numbers.add(new JMenuItem("1234"));
  999.         numbers.add(new JMenuItem("1005"));
  1000.         numbers.add(new JMenuItem("2222"));
  1001.  
  1002.     JMenu drinks = (JMenu) menuBar.add(new JMenu("Drinks"));
  1003.     drinks.setMnemonic('D');
  1004.         drinks.add(new JMenuItem("Thai Iced Tea"));
  1005.         drinks.add(new JMenuItem("Root Beer"));
  1006.         drinks.add(new JMenuItem("Green Tea"));
  1007.         drinks.add(new JMenuItem("Apple Juice"));
  1008.     drinks.addSeparator();
  1009.     ImageIcon softdrink = 
  1010.              loadImageIcon("images/ImageClub/food/softdrink.gif","soft drink");
  1011.         drinks.add(new JMenuItem("Softdrink", softdrink));
  1012.  
  1013.     JMenu music = (JMenu) menuBar.add(new JMenu("Music"));
  1014.     music.setMnemonic('s');
  1015.         music.add(new JMenuItem("Rock"));
  1016.         music.add(new JMenuItem("Country"));
  1017.         music.add(new JMenuItem("Classical"));
  1018.         music.add(new JMenuItem("Jazz"));
  1019.  
  1020.     JMenu food = (JMenu) menuBar.add(new JMenu("Junk Food"));
  1021.     food.setMnemonic('J');
  1022.     ImageIcon burger = loadImageIcon("images/ImageClub/food/burger.gif","burger");
  1023.     ImageIcon fries  = loadImageIcon("images/ImageClub/food/fries.gif","fries");
  1024.     ImageIcon hotdog = loadImageIcon("images/ImageClub/food/hotdog.gif","hot dog");
  1025.     ImageIcon pizza  = loadImageIcon("images/ImageClub/food/pizza.gif","pizza");
  1026.  
  1027.         addMenuItem(food, "Burger", burger);
  1028.     addMenuItem(food, "Fries", fries);
  1029.     addMenuItem(food, "Hotdog", hotdog);
  1030.     addMenuItem(food, "Pizza", pizza);
  1031.  
  1032.     // ********************
  1033.     // ****** ToolBar *****
  1034.     // ********************
  1035.     l = new JLabel("ToolBar:");
  1036.     l.setFont(boldFont);
  1037.     l.setAlignmentX(LEFT_ALIGNMENT);
  1038.     l.setAlignmentY(TOP_ALIGNMENT);
  1039.     p.add(l);
  1040.     p.add(Box.createRigidArea(vpad10));
  1041.  
  1042.     JPanel p1 = (JPanel)p.add(new JPanel());
  1043.     p1.setAlignmentX(LEFT_ALIGNMENT);
  1044.     p1.setAlignmentY(TOP_ALIGNMENT);
  1045.  
  1046.     p1.setLayout(new BorderLayout());
  1047.     JToolBar toolBar = new JToolBar();
  1048.     toolBar.setFloatable(false);
  1049.     toolBar.getAccessibleContext().setAccessibleName(l.getText());
  1050.     addTool(toolBar, "new");
  1051.     addTool(toolBar, "open");
  1052.     addTool(toolBar, "save");
  1053.     toolBar.addSeparator();
  1054.     addTool(toolBar, "cut");
  1055.     addTool(toolBar, "copy");
  1056.     addTool(toolBar, "paste");
  1057.  
  1058.     toolBar.putClientProperty( "JToolBar.isRollover", Boolean.FALSE );
  1059.     l.setLabelFor(toolBar);  // make label Mnemonic go to toolbar
  1060.     l.setDisplayedMnemonic('B');
  1061.  
  1062.     p1.add(toolBar, BorderLayout.NORTH);
  1063.  
  1064.     JPanel textWrapper = new JPanel(new BorderLayout());
  1065.     textWrapper.setAlignmentX(LEFT_ALIGNMENT);
  1066.      textWrapper.setBorder(swing.loweredBorder);
  1067.     
  1068.     p1.add(textWrapper, BorderLayout.CENTER);
  1069.  
  1070.     String text = SwingSet.contentsOfFile("ToolBar.txt");
  1071.     JTextArea textArea = new JTextArea(text);
  1072.     textArea.getAccessibleContext().setAccessibleName("ToolBar information");
  1073.     JScrollPane scroller = new JScrollPane() {
  1074.         public Dimension getPreferredSize() {
  1075.         return new Dimension(10,10);
  1076.         }
  1077.         public float getAlignmentX() {
  1078.         return LEFT_ALIGNMENT;
  1079.         }
  1080.     };
  1081.     scroller.getViewport().add(textArea);
  1082.     textArea.setFont(new Font("Dialog", Font.PLAIN, 12));
  1083.     textWrapper.add(scroller, BorderLayout.CENTER);
  1084.     
  1085.     textArea.setEditable(false);
  1086.     return p;
  1087.     }
  1088.  
  1089.     void createOptionsMenu(JMenuBar menuBar) {
  1090.     JMenu optionMenu = (JMenu)menuBar.add(new JMenu("Dialogs"));
  1091.         optionMenu.setMnemonic('D');
  1092.     JMenuItem item;
  1093.     item = new JMenuItem("Message Dialog");
  1094.     item.addActionListener(new ActionListener() {
  1095.         public void actionPerformed(ActionEvent e) {
  1096.         JOptionPane.showMessageDialog(SwingSet.this, "Plain message");
  1097.         }
  1098.     });
  1099.     optionMenu.add(item);
  1100.  
  1101.     item = new JMenuItem("Warning Dialog");
  1102.     item.addActionListener(new ActionListener() {
  1103.         public void actionPerformed(ActionEvent e) {
  1104.         JOptionPane.showMessageDialog(SwingSet.this, "Example Warning",
  1105.                     "Warning", JOptionPane.WARNING_MESSAGE);
  1106.         }
  1107.     });
  1108.     optionMenu.add(item);
  1109.  
  1110.     item = new JMenuItem("Confirmation Dialog");
  1111.     item.addActionListener(new ActionListener() {
  1112.         public void actionPerformed(ActionEvent e) {
  1113.         int        result;
  1114.         result = JOptionPane.showConfirmDialog(SwingSet.this, "Is SWING cool?");
  1115.         if(result == JOptionPane.YES_OPTION)
  1116.             JOptionPane.showMessageDialog(SwingSet.this, "All right!");
  1117.         else if(result == JOptionPane.NO_OPTION)
  1118.             JOptionPane.showMessageDialog(SwingSet.this, "That is too bad, please send us email describing what you don't like and how we can change it.");
  1119.         }
  1120.     });
  1121.     optionMenu.add(item);
  1122.  
  1123.     item = new JMenuItem("Input Dialog");
  1124.     item.addActionListener(new ActionListener() {
  1125.         public void actionPerformed(ActionEvent e) {
  1126.         String          result;
  1127.  
  1128.         result = JOptionPane.showInputDialog(SwingSet.this, "Please enter your name:");
  1129.         if(result != null) {
  1130.             Object[] message = new Object[2];
  1131.             message[0] = "Thank you for using SWING ";
  1132.             message[1] = result;
  1133.             JOptionPane.showMessageDialog(SwingSet.this, message);
  1134.         }
  1135.         }
  1136.     });
  1137.     optionMenu.add(item);
  1138.  
  1139.     item = new JMenuItem("Component Dialog");
  1140.     item.addActionListener(new ActionListener() {
  1141.         public void actionPerformed(ActionEvent e) {
  1142.         Object[]      message = new Object[4];
  1143.                 JComboBox cb = new JComboBox();
  1144.                 cb.addItem("One");
  1145.                 cb.addItem("Two");
  1146.                 cb.addItem("Three");
  1147.         message[0] = "JOptionPane can contain any number of components, and any number options.";
  1148.         message[1] = new JButton("a button");
  1149.         message[2] = new JTextField("a text field");
  1150.                 message[3] = cb;
  1151.                 
  1152.  
  1153.         String[]      options = { "Option 1", "Option 2", "Option 3",
  1154.                       "Option 4" };
  1155.         JOptionPane.showOptionDialog(SwingSet.this, message, "Example", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[1]);
  1156.         }
  1157.     });
  1158.     optionMenu.add(item);
  1159.     }
  1160.     
  1161.  
  1162.     void addMenuItem(JMenu menu, String text, Icon g) {
  1163.     JMenuItem mi = menu.add(new JMenuItem(text, g));
  1164.     mi.setHorizontalTextPosition(JButton.CENTER);
  1165.     mi.setHorizontalAlignment(JButton.LEFT);
  1166.     mi.setVerticalTextPosition(JButton.BOTTOM);
  1167.     }
  1168.  
  1169.     public void addTool(JToolBar toolBar, String name) {
  1170.     JButton b = 
  1171.            (JButton) toolBar.add(
  1172.                new JButton(loadImageIcon("images/" + name + ".gif",name)));
  1173.     b.setToolTipText(name);
  1174.     b.setMargin(new Insets(0,0,0,0));
  1175.     b.getAccessibleContext().setAccessibleName(name);
  1176.     }
  1177.  
  1178.     /**
  1179.      * Text
  1180.      */
  1181.     JPanel createText() {
  1182.     return new JPanel();
  1183.     }
  1184.  
  1185.     /**
  1186.      * Tab Listener
  1187.      */
  1188.     void createTabListener() {
  1189.     // add listener to know when we've been shown
  1190.         ChangeListener changeListener = new ChangeListener() {
  1191.             public void stateChanged(ChangeEvent e) {
  1192.                 JTabbedPane tab = (JTabbedPane) e.getSource();
  1193.                 int index = tab.getSelectedIndex();
  1194.                 Component currentPage = tab.getComponentAt(index);
  1195.         RepaintManager repaintManager = 
  1196.                     RepaintManager.currentManager(instance);
  1197.  
  1198.         if(!repaintManager.isDoubleBufferingEnabled()) {
  1199.           repaintManager.setDoubleBufferingEnabled(true);
  1200.         }
  1201.  
  1202.         if(previousPage == debugGraphicsPanel) {
  1203.             ((DebugGraphicsPanel)debugGraphicsPanel).resetAll();
  1204.         }
  1205.  
  1206.                 if(currentPage == buttonPanel) {
  1207.             currentControls = buttons;
  1208.         } else if(currentPage == radioButtonPanel) {
  1209.             currentControls = radioButtons;
  1210.         } else if(currentPage == toggleButtonPanel) {
  1211.             currentControls = toggleButtons;
  1212.         } else if(currentPage == checkboxPanel) {
  1213.             currentControls = checkboxes;
  1214.         } else if(currentPage == listBoxPanel) {
  1215.             ((ListPanel)listBoxPanel).resetAll();
  1216.         } else if(currentPage == debugGraphicsPanel) {
  1217.             repaintManager.setDoubleBufferingEnabled(false);
  1218.             invalidate();
  1219.             validate();
  1220.         } else if(currentPage == labelPanel) {
  1221.             currentControls = labels;
  1222.                 }
  1223.                 previousPage = currentPage;
  1224.             }
  1225.         };
  1226.         tabbedPane.addChangeListener(changeListener);
  1227.     }
  1228.  
  1229.  
  1230.  
  1231.     /**
  1232.      *
  1233.      */
  1234.     JPanel createControllButtons() {
  1235.     JPanel p = new JPanel();
  1236.     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  1237.     p.setBorder(emptyBorder5);
  1238.  
  1239.     return p;
  1240.     }
  1241.  
  1242.     /**
  1243.      * create Logo
  1244.      */
  1245.     JPanel createLogo() {
  1246.     JPanel p = new JPanel();
  1247.     p.setLayout(new BorderLayout());
  1248.     ImageIcon logo = loadImageIcon("images/AboutSwing.gif","Swing!");
  1249.     JLabel logoLabel = new JLabel(logo);
  1250.     logoLabel.getAccessibleContext().setAccessibleName("Swing!");
  1251.     p.add(logoLabel, BorderLayout.CENTER);
  1252.     p.setBorder(new MatteBorder(6,6,6,6, SwingSet.sharedInstance().loadImageIcon("images/AboutBorder.gif","About Box Border")));
  1253.  
  1254.     return p;
  1255.     }
  1256.  
  1257.  
  1258.     public static void main(String[] args) {
  1259.         if (args.length == 1) {
  1260.         javaDocPath = args[0];
  1261.         }
  1262.  
  1263.         String vers = System.getProperty("java.version");
  1264.         if (vers.compareTo("1.1.2") < 0) {
  1265.             System.out.println("!!!WARNING: Swing must be run with a " +
  1266.                                "1.1.2 or higher version VM!!!");
  1267.         }
  1268.  
  1269.     // Force SwingSet to come up in the Cross Platform L&F
  1270.     try {
  1271.         UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  1272.         // If you want the System L&F instead, comment out the above line and
  1273.         // uncomment the following:
  1274.         // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  1275.     } catch (Exception exc) {
  1276.         System.out.println("Error loading L&F: " + exc);
  1277.     }
  1278.  
  1279.     WindowListener l = new WindowAdapter() {
  1280.         public void windowClosing(WindowEvent e) {System.exit(0);}
  1281.     };
  1282.  
  1283.     frame = new JFrame("SwingSet");
  1284.     frame.addWindowListener(l);
  1285.     frame.getAccessibleContext().setAccessibleDescription("A sample application to demonstrate the Swing UI components");
  1286.  
  1287.     JOptionPane.setRootFrame(frame);
  1288.  
  1289.     JPanel progressPanel = new JPanel() {
  1290.         public Insets getInsets() {
  1291.         return new Insets(40,30,20,30);
  1292.         }
  1293.     };
  1294.     progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
  1295.     frame.getContentPane().add(progressPanel, BorderLayout.CENTER);
  1296.  
  1297.     Dimension d = new Dimension(400, 20);
  1298.     SwingSet.progressLabel = new JLabel("Loading, please wait...");
  1299.     SwingSet.progressLabel.setAlignmentX(CENTER_ALIGNMENT);
  1300.     SwingSet.progressLabel.setMaximumSize(d);
  1301.     SwingSet.progressLabel.setPreferredSize(d);
  1302.     progressPanel.add(progressLabel);
  1303.     progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
  1304.  
  1305.     SwingSet.progressBar = new JProgressBar();
  1306.     SwingSet.progressLabel.setLabelFor(progressBar);
  1307.     SwingSet.progressBar.setAlignmentX(CENTER_ALIGNMENT);
  1308.     SwingSet.progressBar.setMinimum(0);
  1309.     SwingSet.progressBar.setMaximum(SwingSet.totalPanels);
  1310.     SwingSet.progressBar.setValue(0);
  1311.     SwingSet.progressBar.getAccessibleContext().setAccessibleName("SwingSet loading progress");
  1312.     progressPanel.add(SwingSet.progressBar);
  1313.  
  1314.     // show the frame
  1315.     frame.setSize(INITIAL_WIDTH, INITIAL_HEIGHT);
  1316.     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  1317.     frame.setLocation(screenSize.width/2 - INITIAL_WIDTH/2,
  1318.               screenSize.height/2 - INITIAL_HEIGHT/2);
  1319.     frame.show();
  1320.  
  1321.         frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  1322.  
  1323.     SwingSet sw = new SwingSet();
  1324.     frame.getContentPane().removeAll();
  1325.     frame.getContentPane().setLayout(new BorderLayout());
  1326.     frame.getContentPane().add(sw, BorderLayout.CENTER);
  1327.     frame.setLocation(screenSize.width/2 - WIDTH/2,
  1328.               screenSize.height/2 - HEIGHT/2);
  1329.  
  1330.     frame.setSize(WIDTH, HEIGHT);
  1331.     frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1332.  
  1333.     frame.validate();
  1334.     frame.repaint();
  1335.         sw.requestDefaultFocus();
  1336.     }
  1337.  
  1338.  
  1339.     // Position
  1340.     void setNWposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.TOP);}
  1341.     void setNposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.TOP);}
  1342.     void setNEposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.TOP);}
  1343.     void setWposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.CENTER);}
  1344.     void setCposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.CENTER);}
  1345.     void setEposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.CENTER);}
  1346.     void setSWposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1347.     void setSposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1348.     void setSEposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1349.  
  1350.     void setNWposition(JLabel b) {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.TOP);}
  1351.     void setNposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.TOP);}
  1352.     void setNEposition(JLabel b) {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.TOP);}
  1353.     void setWposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.CENTER);}
  1354.     void setCposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.CENTER);}
  1355.     void setEposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.CENTER);}
  1356.     void setSWposition(JLabel b) {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.BOTTOM);}
  1357.     void setSposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.BOTTOM);}
  1358.     void setSEposition(JLabel b) {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.BOTTOM);}
  1359.  
  1360.     // Alignment
  1361.     void setNWalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.TOP);}
  1362.     void setNalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.TOP);}
  1363.     void setNEalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.TOP);}
  1364.     void setWalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.CENTER);}
  1365.     void setCalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.CENTER);}
  1366.     void setEalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.CENTER);}
  1367.     void setSWalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1368.     void setSalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1369.     void setSEalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1370.  
  1371.     void setNWalignment(JLabel b) {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.TOP);}
  1372.     void setNalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.TOP);}
  1373.     void setNEalignment(JLabel b) {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.TOP);}
  1374.     void setWalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.CENTER);}
  1375.     void setCalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.CENTER);}
  1376.     void setEalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.CENTER);}
  1377.     void setSWalignment(JLabel b) {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.BOTTOM);}
  1378.     void setSalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.BOTTOM);}
  1379.     void setSEalignment(JLabel b) {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.BOTTOM);}
  1380.  
  1381.     /**
  1382.      * Switch the between the Windows, Motif, Mac, and the Metal Look and Feel
  1383.      */
  1384.     class ToggleUIListener implements ItemListener {
  1385.     public void itemStateChanged(ItemEvent e) {
  1386.         Component root = SwingSet.sharedInstance().getRootComponent();
  1387.         root.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  1388.         JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();
  1389.             try {
  1390.            if(rb.isSelected() && rb.getText().equals("Windows Style Look and Feel")) {
  1391.            currentUI = "Windows";
  1392.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  1393.                    tabPlacement.setEnabled(true);
  1394.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1395.            } else if(rb.isSelected() && rb.getText().equals("Macintosh Look and Feel")) {
  1396.            currentUI = "Macintosh";
  1397.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel");
  1398.                    tabPlacement.setEnabled(false);
  1399.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1400.            } else if(rb.isSelected() && rb.getText().equals("Motif Look and Feel")) {
  1401.            currentUI = "Motif";
  1402.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  1403.                    tabPlacement.setEnabled(true);
  1404.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1405.            } else if(rb.isSelected() && rb.getText().equals("Metal Look and Feel")) {
  1406.            currentUI = "Metal";
  1407.                    // com.sun.java.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(
  1408.            //      new com.sun.java.swing.plaf.metal.DefaultMetalTheme());
  1409.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  1410.                    tabPlacement.setEnabled(true);
  1411.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1412.            } 
  1413.            /* non-supported stuff
  1414.            else if(rb.isSelected() && rb.getText().equals(
  1415.                   "Metal Look and Feel (High Contrast Theme)")) {
  1416.                com.sun.java.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(
  1417.               new com.sun.java.swing.plaf.metal.ContrastMetalTheme());
  1418.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  1419.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1420.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Santa Fe)")) {
  1421.                com.sun.java.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1422.               new com.sun.java.swing.plaf.organic.OrganicDefaultTheme());
  1423.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.organic.OrganicLookAndFeel");
  1424.                    tabPlacement.setEnabled(true);
  1425.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1426.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Vancouver)")) {
  1427.                com.sun.java.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1428.               new com.sun.java.swing.plaf.organic.OrganicGrayTheme());
  1429.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.organic.OrganicLookAndFeel");
  1430.                    tabPlacement.setEnabled(true);
  1431.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1432.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Dallas)")) {
  1433.                com.sun.java.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1434.               new com.sun.java.swing.plaf.organic.OrganicBigTheme());
  1435.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.organic.OrganicLookAndFeel");
  1436.                    tabPlacement.setEnabled(true);
  1437.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1438.            }
  1439.                */
  1440.             } catch (UnsupportedLookAndFeelException exc) {
  1441.         // Error - unsupported L&F
  1442.         rb.setEnabled(false);
  1443.                 System.err.println("Unsupported LookAndFeel: " + rb.getText());
  1444.         
  1445.         // Set L&F to Metal
  1446.         try {
  1447.             currentUI = "Metal";
  1448.             metalMenuItem.setSelected(true);
  1449.             UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  1450.             tabPlacement.setEnabled(true);
  1451.             SwingUtilities.updateComponentTreeUI(getRootComponent());
  1452.         } catch (Exception exc2) {
  1453.             System.err.println("Could not load LookAndFeel: " + exc2);
  1454.         }
  1455.             } catch (Exception exc) {
  1456.                 rb.setEnabled(false);
  1457.                 System.err.println("Could not load LookAndFeel: " + rb.getText());
  1458.             }
  1459.  
  1460.         root.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1461.     }
  1462.  
  1463.     }
  1464.             
  1465.  
  1466.    class TabPlacementChanger extends JMenu implements ItemListener {
  1467.        JRadioButtonMenuItem topRb, leftRb, rightRb, bottomRb;
  1468.  
  1469.        public TabPlacementChanger() {
  1470.            super("Tab Placement");
  1471.  
  1472.            ButtonGroup tabGroup = new ButtonGroup();
  1473.  
  1474.            topRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Top"));
  1475.        topRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the top of the window");
  1476.            topRb.setSelected(true);
  1477.            topRb.addItemListener(this);
  1478.            tabGroup.add(topRb);
  1479.         
  1480.            leftRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Left"));
  1481.        leftRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the left of the window");
  1482.            leftRb.addItemListener(this);
  1483.            tabGroup.add(leftRb);
  1484.  
  1485.            bottomRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Bottom"));
  1486.        bottomRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the bottom of the window");
  1487.            bottomRb.addItemListener(this);
  1488.            tabGroup.add(bottomRb);
  1489.  
  1490.            rightRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Right"));
  1491.        rightRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the right of the window");
  1492.            rightRb.addItemListener(this);
  1493.            tabGroup.add(rightRb);
  1494.         }
  1495.  
  1496.     public void itemStateChanged(ItemEvent e) {
  1497.         JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();
  1498.             if (rb.isSelected()) {
  1499.                 String selected = rb.getText();
  1500.                 int placement;
  1501.                 if (selected.equals("Top")) {
  1502.                     placement = JTabbedPane.TOP;
  1503.                 } else if (selected.equals("Left")) {
  1504.                     placement = JTabbedPane.LEFT;
  1505.                 } else if (selected.equals("Bottom")) {
  1506.                     placement = JTabbedPane.BOTTOM;
  1507.                 } else {
  1508.                     placement = JTabbedPane.RIGHT;
  1509.                 }
  1510.                 tabbedPane.setTabPlacement(placement);
  1511.                 tabbedPane.validate();
  1512.             }
  1513.         }
  1514.         public void setEnabled(boolean enabled) {
  1515.             super.setEnabled(enabled);
  1516.             if (!enabled) {
  1517.                 topRb.setSelected(true);
  1518.             } else {
  1519.                 int placement = tabbedPane.getTabPlacement();
  1520.                 switch(placement) {
  1521.                   case JTabbedPane.TOP:
  1522.                       topRb.setSelected(true);
  1523.                       break;
  1524.                   case JTabbedPane.LEFT:
  1525.                       leftRb.setSelected(true);
  1526.                       break;
  1527.                   case JTabbedPane.BOTTOM:
  1528.                       bottomRb.setSelected(true);
  1529.                       break;
  1530.                   case JTabbedPane.RIGHT:
  1531.                       rightRb.setSelected(true);
  1532.                       break;
  1533.                   default:
  1534.                 }
  1535.             }
  1536.         }
  1537.     }
  1538.                     
  1539.  
  1540.     // ***********************************************************
  1541.     // *********** Create the button controls listeners **********
  1542.     // ***********************************************************
  1543.     ItemListener buttonPadListener = new ItemListener() {
  1544.     Component c;
  1545.     AbstractButton b;
  1546.  
  1547.     public void itemStateChanged(ItemEvent e) {
  1548.         // *** pad = 0
  1549.         int pad = 0;
  1550.         JRadioButton rb = (JRadioButton) e.getSource();
  1551.         if(rb.getText().equals("Default")) {
  1552.         for(int i = 0; i < currentControls.size(); i++) {
  1553.             b = (AbstractButton) currentControls.elementAt(i);
  1554.                 // *** pad = Default
  1555.             b.setMargin(null);
  1556.         }
  1557.         int index = tabbedPane.getSelectedIndex();
  1558.         Component currentPage = tabbedPane.getComponentAt(index);
  1559.         currentPage.invalidate();
  1560.         currentPage.validate();
  1561.         currentPage.repaint();
  1562.         return;
  1563.         } else if(rb.getText().equals("10")) {
  1564.             // pad = 10
  1565.         pad = 10;
  1566.         }
  1567.  
  1568.         for(int i = 0; i < currentControls.size(); i++) {
  1569.         b = (AbstractButton) currentControls.elementAt(i);
  1570.         b.setMargin(new Insets(pad,pad,pad,pad));
  1571.         }
  1572.         int index = tabbedPane.getSelectedIndex();
  1573.         Component currentPage = tabbedPane.getComponentAt(index);
  1574.         currentPage.invalidate();
  1575.         currentPage.validate();
  1576.         currentPage.repaint();
  1577.     }
  1578.     };
  1579.  
  1580.     ItemListener buttonDisplayListener = new ItemListener() {
  1581.     Component c;
  1582.     AbstractButton b;
  1583.  
  1584.     public void itemStateChanged(ItemEvent e) {
  1585.         JCheckBox cb = (JCheckBox) e.getSource();
  1586.         if(cb.getText().equals("Enabled")) {
  1587.         for(int i = 0; i < currentControls.size(); i++) {
  1588.             c = (Component) currentControls.elementAt(i);
  1589.             c.setEnabled(cb.isSelected());
  1590.             c.invalidate();
  1591.         }
  1592.         } else if(cb.getText().equals("Paint Border")) {
  1593.         c = (Component) currentControls.elementAt(0);
  1594.         if(c instanceof AbstractButton) {
  1595.             for(int i = 0; i < currentControls.size(); i++) {
  1596.             b = (AbstractButton) currentControls.elementAt(i);
  1597.             b.setBorderPainted(cb.isSelected());
  1598.                 b.invalidate();
  1599.             }
  1600.         }
  1601.         } else if(cb.getText().equals("Paint Focus")) {
  1602.         c = (Component) currentControls.elementAt(0);
  1603.         if(c instanceof AbstractButton) {
  1604.             for(int i = 0; i < currentControls.size(); i++) {
  1605.             b = (AbstractButton) currentControls.elementAt(i);
  1606.             b.setFocusPainted(cb.isSelected());
  1607.                 b.invalidate();
  1608.             }
  1609.         }
  1610.         }
  1611.         int index = tabbedPane.getSelectedIndex();
  1612.         Component currentPage = tabbedPane.getComponentAt(index);
  1613.         currentPage.invalidate();
  1614.         currentPage.validate();
  1615.         currentPage.repaint();
  1616.     }
  1617.     };
  1618.  
  1619.     // Text Position
  1620.     ActionListener textPositionListener = new ActionListener() {
  1621.     public void actionPerformed(ActionEvent e) {
  1622.         JRadioButton rb = (JRadioButton) e.getSource();
  1623.         if(rb.isSelected()) {
  1624.         if(rb.getActionCommand().equals("NW")) {
  1625.             for(int i = 0; i < currentControls.size(); i++) {
  1626.             Component c = (Component) currentControls.elementAt(i);
  1627.             if(c instanceof AbstractButton) {
  1628.                 AbstractButton x = (AbstractButton) c;
  1629.                 setNWposition(x);
  1630.             } else if(c instanceof JLabel) {
  1631.                 JLabel x = (JLabel) c;
  1632.                 setNWposition(x);
  1633.             }
  1634.             }
  1635.         } else if(rb.getActionCommand().equals("N")) {
  1636.             for(int i = 0; i < currentControls.size(); i++) {
  1637.             Component c = (Component) currentControls.elementAt(i);
  1638.             if(c instanceof AbstractButton) {
  1639.                 AbstractButton x = (AbstractButton) c;
  1640.                 setNposition(x);
  1641.             } else if(c instanceof JLabel) {
  1642.                 JLabel x = (JLabel) c;
  1643.                 setNposition(x);
  1644.             }
  1645.             }
  1646.         } else if(rb.getActionCommand().equals("NE")) {
  1647.             for(int i = 0; i < currentControls.size(); i++) {
  1648.             Component c = (Component) currentControls.elementAt(i);
  1649.             if(c instanceof AbstractButton) {
  1650.                 AbstractButton x = (AbstractButton) c;
  1651.                 setNEposition(x);
  1652.             } else if(c instanceof JLabel) {
  1653.                 JLabel x = (JLabel) c;
  1654.                 setNEposition(x);
  1655.             }
  1656.             }
  1657.         } else if(rb.getActionCommand().equals("W")) {
  1658.             for(int i = 0; i < currentControls.size(); i++) {
  1659.             Component c = (Component) currentControls.elementAt(i);
  1660.             if(c instanceof AbstractButton) {
  1661.                 AbstractButton x = (AbstractButton) c;
  1662.                 setWposition(x);
  1663.             } else if(c instanceof JLabel) {
  1664.                 JLabel x = (JLabel) c;
  1665.                 setWposition(x);
  1666.             }
  1667.             }
  1668.         } else if(rb.getActionCommand().equals("C")) {
  1669.             for(int i = 0; i < currentControls.size(); i++) {
  1670.             Component c = (Component) currentControls.elementAt(i);
  1671.             if(c instanceof AbstractButton) {
  1672.                 AbstractButton x = (AbstractButton) c;
  1673.                 setCposition(x);
  1674.             } else if(c instanceof JLabel) {
  1675.                 JLabel x = (JLabel) c;
  1676.                 setCposition(x);
  1677.             }
  1678.             }
  1679.         } else if(rb.getActionCommand().equals("E")) {
  1680.             for(int i = 0; i < currentControls.size(); i++) {
  1681.             Component c = (Component) currentControls.elementAt(i);
  1682.             if(c instanceof AbstractButton) {
  1683.                 AbstractButton x = (AbstractButton) c;
  1684.                 setEposition(x);
  1685.             } else if(c instanceof JLabel) {
  1686.                 JLabel x = (JLabel) c;
  1687.                 setEposition(x);
  1688.             }
  1689.             }
  1690.         } else if(rb.getActionCommand().equals("SW")) {
  1691.             for(int i = 0; i < currentControls.size(); i++) {
  1692.             Component c = (Component) currentControls.elementAt(i);
  1693.             if(c instanceof AbstractButton) {
  1694.                 AbstractButton x = (AbstractButton) c;
  1695.                 setSWposition(x);
  1696.             } else if(c instanceof JLabel) {
  1697.                 JLabel x = (JLabel) c;
  1698.                 setSWposition(x);
  1699.             }
  1700.             }
  1701.         } else if(rb.getActionCommand().equals("S")) {
  1702.             for(int i = 0; i < currentControls.size(); i++) {
  1703.             Component c = (Component) currentControls.elementAt(i);
  1704.             if(c instanceof AbstractButton) {
  1705.                 AbstractButton x = (AbstractButton) c;
  1706.                 setSposition(x);
  1707.             } else if(c instanceof JLabel) {
  1708.                 JLabel x = (JLabel) c;
  1709.                 setSposition(x);
  1710.             }
  1711.             }
  1712.         } else if(rb.getActionCommand().equals("SE")) {
  1713.             for(int i = 0; i < currentControls.size(); i++) {
  1714.             Component c = (Component) currentControls.elementAt(i);
  1715.             if(c instanceof AbstractButton) {
  1716.                 AbstractButton x = (AbstractButton) c;
  1717.                 setSEposition(x);
  1718.             } else if(c instanceof JLabel) {
  1719.                 JLabel x = (JLabel) c;
  1720.                 setSEposition(x);
  1721.             }
  1722.             }
  1723.         }
  1724.         int index = tabbedPane.getSelectedIndex();
  1725.                 Component currentPage = tabbedPane.getComponentAt(index);
  1726.         currentPage.invalidate();
  1727.         currentPage.validate();
  1728.         currentPage.repaint();
  1729.         } else {
  1730.         }
  1731.     }
  1732.     };
  1733.  
  1734.  
  1735.     // Label Alignment
  1736.     ActionListener labelAlignmentListener = new ActionListener() {
  1737.     public void actionPerformed(ActionEvent e) {
  1738.         JRadioButton rb = (JRadioButton) e.getSource();
  1739.         if(rb.isSelected()) {
  1740.         if(rb.getActionCommand().equals("NW")) {
  1741.             for(int i = 0; i < currentControls.size(); i++) {
  1742.             Component c = (Component) currentControls.elementAt(i);
  1743.             if(c instanceof AbstractButton) {
  1744.                 AbstractButton x = (AbstractButton) c;
  1745.                 setNWalignment(x);
  1746.                 x.invalidate();
  1747.             } else if(c instanceof JLabel) {
  1748.                 JLabel x = (JLabel) c;
  1749.                 setNWalignment(x);
  1750.                 x.invalidate();
  1751.             }
  1752.             }
  1753.         } else if(rb.getActionCommand().equals("N")) {
  1754.             for(int i = 0; i < currentControls.size(); i++) {
  1755.             Component c = (Component) currentControls.elementAt(i);
  1756.             if(c instanceof AbstractButton) {
  1757.                 AbstractButton x = (AbstractButton) c;
  1758.                 setNalignment(x);
  1759.                 x.invalidate();
  1760.             } else if(c instanceof JLabel) {
  1761.                 JLabel x = (JLabel) c;
  1762.                 setNalignment(x);
  1763.                 x.invalidate();
  1764.             }
  1765.             }
  1766.         } else if(rb.getActionCommand().equals("NE")) {
  1767.             for(int i = 0; i < currentControls.size(); i++) {
  1768.             Component c = (Component) currentControls.elementAt(i);
  1769.             if(c instanceof AbstractButton) {
  1770.                 AbstractButton x = (AbstractButton) c;
  1771.                 setNEalignment(x);
  1772.                 x.invalidate();
  1773.             } else if(c instanceof JLabel) {
  1774.                 JLabel x = (JLabel) c;
  1775.                 setNEalignment(x);
  1776.                 x.invalidate();
  1777.             }
  1778.             }
  1779.         } else if(rb.getActionCommand().equals("W")) {
  1780.             for(int i = 0; i < currentControls.size(); i++) {
  1781.             Component c = (Component) currentControls.elementAt(i);
  1782.             if(c instanceof AbstractButton) {
  1783.                 AbstractButton x = (AbstractButton) c;
  1784.                 setWalignment(x);
  1785.                 x.invalidate();
  1786.             } else if(c instanceof JLabel) {
  1787.                 JLabel x = (JLabel) c;
  1788.                 setWalignment(x);
  1789.                 x.invalidate();
  1790.             }
  1791.             }
  1792.         } else if(rb.getActionCommand().equals("C")) {
  1793.             for(int i = 0; i < currentControls.size(); i++) {
  1794.             Component c = (Component) currentControls.elementAt(i);
  1795.             if(c instanceof AbstractButton) {
  1796.                 AbstractButton x = (AbstractButton) c;
  1797.                 setCalignment(x);
  1798.                 x.invalidate();
  1799.             } else if(c instanceof JLabel) {
  1800.                 JLabel x = (JLabel) c;
  1801.                 setCalignment(x);
  1802.                 x.invalidate();
  1803.             }
  1804.             }
  1805.         } else if(rb.getActionCommand().equals("E")) {
  1806.             for(int i = 0; i < currentControls.size(); i++) {
  1807.             Component c = (Component) currentControls.elementAt(i);
  1808.             if(c instanceof AbstractButton) {
  1809.                 AbstractButton x = (AbstractButton) c;
  1810.                 setEalignment(x);
  1811.                 x.invalidate();
  1812.             } else if(c instanceof JLabel) {
  1813.                 JLabel x = (JLabel) c;
  1814.                 setEalignment(x);
  1815.                 x.invalidate();
  1816.             }
  1817.             }
  1818.         } else if(rb.getActionCommand().equals("SW")) {
  1819.             for(int i = 0; i < currentControls.size(); i++) {
  1820.             Component c = (Component) currentControls.elementAt(i);
  1821.             if(c instanceof AbstractButton) {
  1822.                 AbstractButton x = (AbstractButton) c;
  1823.                 setSWalignment(x);
  1824.                 x.invalidate();
  1825.             } else if(c instanceof JLabel) {
  1826.                 JLabel x = (JLabel) c;
  1827.                 setSWalignment(x);
  1828.                 x.invalidate();
  1829.             }
  1830.             }
  1831.         } else if(rb.getActionCommand().equals("S")) {
  1832.             for(int i = 0; i < currentControls.size(); i++) {
  1833.             Component c = (Component) currentControls.elementAt(i);
  1834.             if(c instanceof AbstractButton) {
  1835.                 AbstractButton x = (AbstractButton) c;
  1836.                 setSalignment(x);
  1837.                 x.invalidate();
  1838.             } else if(c instanceof JLabel) {
  1839.                 JLabel x = (JLabel) c;
  1840.                 setSalignment(x);
  1841.                 x.invalidate();
  1842.             }
  1843.             }
  1844.         } else if(rb.getActionCommand().equals("SE")) {
  1845.             for(int i = 0; i < currentControls.size(); i++) {
  1846.             Component c = (Component) currentControls.elementAt(i);
  1847.             if(c instanceof AbstractButton) {
  1848.                 AbstractButton x = (AbstractButton) c;
  1849.                 setSEalignment(x);
  1850.                 x.invalidate();
  1851.             } else if(c instanceof JLabel) {
  1852.                 JLabel x = (JLabel) c;
  1853.                 setSEalignment(x);
  1854.                 x.invalidate();
  1855.             }
  1856.             }
  1857.         }
  1858.         int index = tabbedPane.getSelectedIndex();
  1859.                 Component currentPage = tabbedPane.getComponentAt(index);
  1860.         currentPage.invalidate();
  1861.         currentPage.validate();
  1862.         currentPage.repaint();
  1863.         }
  1864.     }
  1865.     };
  1866.  
  1867.     // Title Pane tile position
  1868.     ActionListener borderedPaneListener = new ActionListener() {
  1869.     public void actionPerformed(ActionEvent e) {
  1870.         JRadioButton b = (JRadioButton) e.getSource();
  1871.         if(b.getText().equals("Above Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.ABOVE_TOP);}
  1872.         if(b.getText().equals("Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.TOP);}
  1873.         if(b.getText().equals("Below Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BELOW_TOP);}
  1874.  
  1875.         if(b.getText().equals("Above Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.ABOVE_BOTTOM);}
  1876.         if(b.getText().equals("Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BOTTOM);}
  1877.         if(b.getText().equals("Below Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BELOW_BOTTOM);}
  1878.  
  1879.         if(b.getText().equals("Left")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.LEFT);}
  1880.         if(b.getText().equals("Center")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.CENTER);}
  1881.         if(b.getText().equals("Right")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.RIGHT);}
  1882.  
  1883.         borderedPane.invalidate();
  1884.         borderedPane.validate();
  1885.         borderedPane.repaint();
  1886.     }
  1887.     };
  1888.  
  1889.     public static JPanel createHorizontalPanel(boolean threeD) {
  1890.     JPanel p = new JPanel();
  1891.     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
  1892.     if(threeD) {
  1893.         p.setBorder(loweredBorder);
  1894.     }
  1895.     return p;
  1896.     }
  1897.  
  1898.     public static JPanel createVerticalPanel(boolean threeD) {
  1899.     JPanel p = new JPanel();
  1900.     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  1901.     if(threeD) {
  1902.         p.setBorder(loweredBorder);
  1903.     }    
  1904.     return p;
  1905.     }
  1906.  
  1907.     public static String contentsOfFile(String filename) {
  1908.     String s = new String();
  1909.     File f;
  1910.     char[] buff = new char[50000];
  1911.     InputStream is;
  1912.     InputStreamReader reader;
  1913.     boolean fromApplet = SwingSet.sharedInstance().isApplet();
  1914.     URL url;
  1915.  
  1916.     try {
  1917.       if(fromApplet) {
  1918.         url = new URL(SwingSet.sharedInstance().getApplet().getCodeBase(),filename);
  1919.         is = url.openStream();
  1920.         reader = new InputStreamReader(is);
  1921.       } else {
  1922.         f = new File(filename);
  1923.         reader = new FileReader(f);
  1924.       }
  1925.       int nch;
  1926.       while ((nch = reader.read(buff, 0, buff.length)) != -1) {
  1927.         s = s + new String(buff, 0, nch);
  1928.       }
  1929.     } catch (java.io.IOException ex) {
  1930.         s = "Could not load file: " + filename;
  1931.     }
  1932.  
  1933.     return s;
  1934.     }
  1935.  
  1936.     class ColoredSquare implements Icon {
  1937.     Color color;
  1938.     public ColoredSquare(Color c) {
  1939.         this.color = c;
  1940.     }
  1941.  
  1942.     public void paintIcon(Component c, Graphics g, int x, int y) {
  1943.         Color oldColor = g.getColor();
  1944.         g.setColor(color);
  1945.         g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
  1946.         g.setColor(oldColor);
  1947.     }
  1948.     public int getIconWidth() { return 12; }
  1949.     public int getIconHeight() { return 12; }
  1950.  
  1951.     }
  1952.  
  1953.   public ImageIcon loadImageIcon(String filename, String description) {
  1954.     if(applet == null) {
  1955.       return new ImageIcon(filename, description);
  1956.     } else {
  1957.       URL url;
  1958.       try {
  1959.     url = new URL(applet.getCodeBase(),filename);
  1960.       } catch(MalformedURLException e) {
  1961.       System.err.println("Error trying to load image " + filename);
  1962.       return null;
  1963.       }
  1964.       return new ImageIcon(url, description);
  1965.     }
  1966.   }
  1967.  
  1968.   public static SwingSet sharedInstance() {
  1969.     return instance;
  1970.   }
  1971.  
  1972.   public java.applet.Applet getApplet() {
  1973.     return applet;
  1974.   }
  1975.  
  1976.   public boolean isApplet() {
  1977.     return (applet != null);
  1978.   }
  1979.  
  1980.   public Container getRootComponent() {
  1981.     if(isApplet())
  1982.       return applet;
  1983.     else
  1984.       return frame;
  1985.   }
  1986.  
  1987.   public Frame getFrame() {
  1988.     if(isApplet()) {
  1989.       Container parent;
  1990.       for(parent = getApplet(); parent != null && !(parent instanceof Frame) ; parent = parent.getParent());
  1991.       if(parent != null)
  1992.     return (Frame)parent;
  1993.       else
  1994.     return null;
  1995.     } else
  1996.       return frame;
  1997.   }
  1998.  
  1999.   class FilePreviewer extends JComponent implements PropertyChangeListener {
  2000.       ImageIcon thumbnail = null;
  2001.       File f = null;
  2002.       
  2003.       public FilePreviewer(JFileChooser fc) {
  2004.       setPreferredSize(new Dimension(100, 50));
  2005.       fc.addPropertyChangeListener(this);
  2006.       }
  2007.       
  2008.       public void loadImage() {
  2009.       if(f != null) {
  2010.           ImageIcon tmpIcon = new ImageIcon(f.getPath());
  2011.           if(tmpIcon.getIconWidth() > 90) {
  2012.           thumbnail = new ImageIcon(
  2013.               tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
  2014.           } else {
  2015.           thumbnail = tmpIcon;
  2016.           }
  2017.       }
  2018.       }
  2019.       
  2020.       public void propertyChange(PropertyChangeEvent e) {
  2021.       String prop = e.getPropertyName();
  2022.       if(prop == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
  2023.           f = (File) e.getNewValue();
  2024.           if(isShowing()) {
  2025.           loadImage();
  2026.           repaint();
  2027.           }
  2028.       }
  2029.       }
  2030.       
  2031.       public void paint(Graphics g) {
  2032.       if(thumbnail == null) {
  2033.           loadImage();
  2034.       }
  2035.       if(thumbnail != null) {
  2036.           int x = getWidth()/2 - thumbnail.getIconWidth()/2;
  2037.           int y = getHeight()/2 - thumbnail.getIconHeight()/2;
  2038.           if(y < 0) {
  2039.           y = 0;
  2040.           }
  2041.           
  2042.           if(x < 5) {
  2043.           x = 5;
  2044.           }
  2045.           thumbnail.paintIcon(this, g, x, y);
  2046.       }
  2047.       }
  2048.   }
  2049. }
  2050.